<template>
  <div class="welcome-view">
    <div class="welcome-container">
      <h2>欢迎回来</h2>
      <div class="user-info">
        <p>您已成功登录系统</p>
        <p>Token: {{ token }}</p>
      </div>
      <button class="logout-btn" @click="handleLogout">退出登录</button>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'

export default defineComponent({
  name: 'WelcomeView',
  setup() {
    const router = useRouter()
    const token = ref('')

    onMounted(() => {
      const storedToken = localStorage.getItem('token')
      if (storedToken) {
        token.value = storedToken
      } else {
        router.push('/login')
      }
    })

    const handleLogout = () => {
      localStorage.removeItem('token')
      router.push('/login')
    }

    return {
      token,
      handleLogout
    }
  }
})
</script>

<style scoped>
.welcome-view {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f5f5f5;
}

.welcome-container {
  background-color: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 400px;
  text-align: center;
}

h2 {
  color: #333;
  margin-bottom: 2rem;
}

.user-info {
  margin-bottom: 2rem;
  padding: 1rem;
  background-color: #f8f9fa;
  border-radius: 4px;
}

.user-info p {
  margin: 0.5rem 0;
  color: #666;
}

.logout-btn {
  padding: 0.75rem 2rem;
  background-color: #dc3545;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.logout-btn:hover {
  background-color: #c82333;
}
</style> 